/**
 * Created by Administrator on 2017-03-30 030.
 */
window.onload = function () {
    var myJd = document.getElementsByClassName('myjd')[0];
    var navDiv = document.getElementsByClassName('nav_div')[0];
    var navLi = document.getElementsByClassName('nav_li')[0];
    var navLi1 = document.getElementsByClassName('nav_li1')[0];
    var navLi2 = document.getElementsByClassName('nav_li2')[0];
    var navLi3 = document.getElementsByClassName('nav_li3')[0];
    var gZjd = document.getElementsByClassName('gzjd')[0];
    var keHufuwu = document.getElementsByClassName('kehufuwu')[0];
    var wZdh = document.getElementsByClassName('wzdh')[0];
    var jdPhone = document.getElementsByClassName('jdphone')[0];
    var gou1 = document.getElementsByClassName('gou1')[0];
    var navNone = document.getElementsByClassName('nav_none')[0];
    var myLi = document.getElementsByClassName('myli')[0];
    var oGouwuche = document.getElementsByClassName('logo_gouwuche')[0];
    var close = document.getElementsByClassName('close')[0];
    var banner1 = document.getElementsByClassName('banner')[0];
    var d1 = document.getElementsByClassName('d1')[0];
    var d2 = document.getElementsByClassName('d2')[0];
    var oI = document.getElementsByClassName('content_center')[0];
    var oConLf = document.getElementsByClassName('con_lf');
    var oConDl= document.getElementsByClassName('con_d1');
    var oImg2= document.getElementsByClassName('img2');
    var banner = document.getElementById('con_ul');
    var controls = document.getElementById('content_ul');
    var controlsLis=controls.getElementsByTagName("li");
    var oSales = document.getElementById('sales');
    var oNotice = document.getElementById('notice');
    var oConNotice= document.getElementsByClassName('content_notice')[0];
    var oConNotice1= document.getElementsByClassName('content_notice1')[0];
    var oHf1 = document.getElementsByClassName('hf1');
    var oHf1d = document.getElementsByClassName('hf1_d');
    var cdItemtxt = document.getElementsByClassName('cd_item_txt')[0];
    var cdItemtxt1 = document.getElementsByClassName('cd_item_txt')[1];
    var cdItemtxt2 = document.getElementsByClassName('cd_item_txt')[2];
    //倒计时
    var n = 60;
    // var m = 10;
    var h = 24;
    var date = new Date();
    var hh = date.getHours();
    var mm = date.getMinutes();
    var ht = h - hh;
    if ( ht < 10) {
        ht = '0'+ht;
    }
    if ( mm < 10) {
        mm = '0'+mm;
    }
    cdItemtxt.innerHTML = ht;
    cdItemtxt1.innerHTML = mm;
    function time() {
        n--;
        if ( n < 10 ) {
            n = '0'+n;
        }
        cdItemtxt2.innerHTML = n;
        if ( n == 0 ) {
            if ( mm == 0) {
                mm = 60;
                ht--;
                if ( ht < 10) {
                    ht = '0'+ht;
                }
                cdItemtxt.innerHTML = ht;
                if ( ht == 0 ) {
                    clearInterval(tt);
                    alert("活动结束！！");
                }
            }
            mm--;
            if ( mm < 10) {
                mm = '0'+mm;
            }
            cdItemtxt1.innerHTML = mm;
            n = 60;
        }
    }
    var tt = setInterval(time,1000);
    //生活服务
    for (var w = 0; w < 4; w++) {
        oHf1[w].index = w;
        oHf1[w].onmouseover = function () {
            oHf1d[this.index].style.display = 'block';
        }
        oHf1[w].onmouseout = function () {
            oHf1d[this.index].style.display = 'none';
        }
    }
    /*tab 状态栏*/
    oSales.onmouseover = function () {
        oConNotice.style.display = 'block';
        this.style.borderBottom = '4px solid #C91623';
        oNotice.style.borderBottom = '';
        oConNotice1.style.display = 'none';
    }
    oNotice.onmouseover = function () {
        oConNotice1.style.display = 'block';
        this.style.borderBottom = '4px solid #C91623'
        oSales.style.borderBottom = '1px solid #ddd';
        oConNotice.style.display = 'none';
    }

    /*轮播图*/
    var timer=null;//设置定时器
    var num=0;
    var index = 1;
    for(var i=0;i<controlsLis.length;i++){
        controlsLis[i].index=i;
        controlsLis[i].onmouseover=function(){
            for(var j=0;j<controlsLis.length;j++){
                controlsLis[j].className=''//把所有的控制按钮颜色都去掉
            }
            this.className='star';//当前点击的按钮变色
            banner.style.left=-708*this.index+"px";
            num=this.index;
            autoPlay();
        }
    }
    timer=setInterval(autoPlay,2000);
    function autoPlay() {
            if(num>4){
                num=0;
            }
            for(var j=0;j<controlsLis.length;j++){
                controlsLis[j].className=''//把所有的控制按钮颜色都去掉
            }
            controlsLis[num].className='star';
            banner.style.left=-708*num+"px";
            num++;
        }
    oI.onmouseover = function () {
        d1.style.display = 'block';
        d2.style.display = 'block';
        clearInterval(timer);
    }
    oI.onmouseout = function () {
        d1.style.display = 'none';
        d2.style.display = 'none';
        timer = setInterval(autoPlay,2000);
    }
        function oContentShow() {
            //将之前的小圆点的样式清除
            for (var y = 0; y < controlsLis.length; y++) {
                if (controlsLis[y].className == "star") {
                    controlsLis[y].className = "";
                }
            }
            //数组从0开始，故index需要-1
            controlsLis[index - 1].className = "star";
        }

        d2.addEventListener('click',autoPlay);
        d1.addEventListener('click',back);
        function back() {
            num--;
            if(num < 0){
                num=4;
            }
            for(var j=0;j<controlsLis.length;j++){
                controlsLis[j].className=''//把所有的控制按钮颜色都去掉
            }
            controlsLis[num].className='star';
            banner.style.left=-708*num+"px";
        }

        // 家用电器
        for (var t = 0; t < oConLf.length;t++) {
            oConLf[t].index = t;
            oConLf[t].onmouseover = function () {
                oConDl[this.index].style.display = 'block';
                this.style.background = '#999395';
            }
            oConLf[t].onmouseout = function () {
                oConDl[this.index].style.display = 'none';
                this.style.background = '';
            }

        }

          navNone.onmouseover = function () {
              navDiv.style.display = 'block';
              this.style.paddingBottom = '20px';
              this.style.border = '1px solid #ddd';
              this.style.background = 'white';
          }
          navNone.onmouseout = function () {
            navDiv.style.display = 'none';
            this.style.paddingBottom = '';
            this.style.background = '';
            this.style.border = '';
        }
        myLi.onmouseover = function () {
            myJd.style.display = 'block';
            this.style.paddingBottom = '8px';
            this.style.border = '1px solid #ddd';
            this.style.background = 'white';
        }
        myLi.onmouseout = function () {
            myJd.style.display = 'none';
            this.style.paddingBottom = '';
            this.style.background = '';
            this.style.border = '';
        }
        navLi.onmouseover = function () {
            jdPhone.style.display = 'block';
            this.style.paddingBottom = '8px';
            this.style.border = '1px solid #ddd';
            this.style.background = 'white';
        }
        navLi.onmouseout = function () {
            jdPhone.style.display = 'none';
            this.style.paddingBottom = '';
            this.style.background = '';
            this.style.border = '';
        }
        navLi1.onmouseover = function () {
            gZjd.style.display = 'block';
            this.style.paddingBottom = '8px';
            this.style.border = '1px solid #ddd';
            this.style.background = 'white';
        }
        navLi1.onmouseout = function () {
            gZjd.style.display = 'none';
            this.style.paddingBottom = '';
            this.style.background = '';
            this.style.border = '';
        }
        navLi2.onmouseover = function () {
            keHufuwu.style.display = 'block';
            this.style.paddingBottom = '8px';
            this.style.border = '1px solid #ddd';
            this.style.background = 'white';
        }
        navLi2.onmouseout = function () {
            keHufuwu.style.display = 'none';
            this.style.paddingBottom = '';
            this.style.background = '';
            this.style.border = '';
        }
        navLi3.onmouseover = function () {
            wZdh.style.display = 'block';
            this.style.paddingBottom = '8px';
            this.style.border = '1px solid #ddd';
            this.style.background = 'white';
        }
        navLi3.onmouseout = function () {
            wZdh.style.display = 'none';
            this.style.paddingBottom = '';
            this.style.background = '';
            this.style.border = '';
        }
        oGouwuche.onmouseover = function () {
            this.style.paddingBottom = '40px';
            this.style.background = 'white';
            gou1.style.display = 'block';
        }
        oGouwuche.onmouseout = function () {
            this.style.paddingBottom = '';
            gou1.style.display = 'none';
        }
        d1.onmouseover = function () {
            this.style.background = '#000';
        }
        d1.onmouseout = function () {
            this.style.background = '';
        }
        d2.onmouseover = function () {
            this.style.background = '#000';
        }
        d2.onmouseout = function () {
            this.style.background = '';
        }
        close.addEventListener('click',fn);
        function fn() {
            banner1.style.display = 'none';
        }
      //京喜夜图片
       for (var x = 0; x < oImg2.length; x++) {
           oImg2[x].onmouseover = function () {
               this.style.marginTop = '8px';
           }
           oImg2[x].onmouseout = function () {
               this.style.marginTop = '';
           }
       }
}